<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Visitor;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Api\V1\Resources\VideoResource;
use App\Supports\LinkedIn\Client;

class VisitorsController extends Controller
{
	
	public function records()
	{

		$visitorStr = request('visitor_str', '');
		if($visitorStr){

			$visitor = Visitor::query()->where("visitor_str",$visitorStr)->first();
			if(!$visitor){

				$visitor = Visitor::create(['visitor_str'=>$visitorStr]);
			}

			$visitor->records()->create([
				'visit_url'=>request('visit_url'),
				'stayduration'=>request('stayduration') ?? 0,
			]);

		}

		
	}


	public function update()
	{

		$visitorStr = request('visitor_str', '');
		if($visitorStr){

			$visitor = Visitor::query()->where("visitor_str",$visitorStr)->first();
			if(!$visitor){

				$visitor = Visitor::create(['visitor_str'=>$visitorStr]);
			}

			$visitor->records()->where('visit_url',request('visit_url'))->where('stayduration',0)->update([
				'stayduration'=>request('stayduration') ?? 0,
			]);

		}

		
	}

}
